<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>后台主界面</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" href='<?php echo $static_url; ?>common/css/admin.css' type="text/css" />
<link rel="stylesheet" href='<?php echo $static_url; ?>common/css/daily_record.css' type="text/css" />
<link rel="stylesheet" href='<?php echo $static_url; ?>common/css/treeview.css' type="text/css" />
<link rel="stylesheet" href='<?php echo $static_url; ?>common/css/news_list.css' type="text/css" />
<link rel="stylesheet" href='<?php echo $static_url; ?>common/css/news_add.css' type="text/css" />
<script src="<?php echo $static_url; ?>common/js/jquery-1.8.3.min.js" type="text/javascript"></script>
<script src="<?php echo $static_url; ?>common/js/common.js" type="text/javascript"></script>
<script src="<?php echo $static_url; ?>common/js/jquery.treeview.js" type="text/javascript"></script>
<script src="<?php echo $static_url; ?>ueditor/ueditor.config.js" type="text/javascript"></script>
<script src="<?php echo $static_url; ?>ueditor/ueditor.all.js" type="text/javascript"></script>
</head>
<body class="body_background">
	<div>
		<?php echo $header_nav; ?>
		<div class="common_container clearfix">
			<div class="crumbs">
				<span class="catalogue">文章管理</span>
				<a href="/www/admin/news/news_lists.php">文章列表</a> |
				<a href="/www/admin/news/news_add.php?category_id=<?php echo $category_id; ?>">添加文章</a> |
				<a href="/www/admin/news/empty_add.php?category_id=<?php echo $category_id; ?>">添加空白文章</a> |
				<a href="/www/admin/news/news_relative.php">手动推荐</a> |
				<a href="/www/admin/news/news_recover.php">回收站</a>
			</div>
			<div class="treeview_container" id="side_container">
				<div class="closeSidebar"><i title="点击隐藏左菜单" class="icon_close"></i></div>
				<h4>文章栏目</h4>
				<ul id="browser" class="filetree"></ul>
			</div>
			<div class="sidebar_container_hidden" style="margin-top:10px;margin-right:5px;"  >
				<div class="openSidebar"><i title="点击显示左菜单" class="icon_open"></i></div>
			</div>
			<div class="daily_record_main">
				<div class="news_add_container" id="main_container" >
					<table class="record_tips"><tr><td class="colorstyle">添加空白文章</td></tr></table>
					<form action="/www/admin/news/do/do_add_empty.php" method="post" enctype="multipart/form-data" onsubmit="return do_submit();">
					<table class="news_add_table">
						<tr>
							<td class="tleft w100">
								<span style="color:#f00;">*</span>
								<span class="fontWeight">栏目</span>
							</td>
							<td>
								<div id="category"></div>
							</td>
						</tr>
						<tr>
							<td class="tleft w100">
								<span style="color:#f00;">*</span>
								<span class="fontWeight">标题</span>
							</td>
							<td>
								<input type="text" class="ipt_wid415" name="title" id="title" />
								<span id="title_strlen"></span>
							</td>
						</tr>
						<tr>
							<td class="tleft w100">
								<span style="color:#f00;">*</span>
								<span class="fontWeight">外部链接</span>
							</td>
							<td>
								<input type="text" class="ipt_wid415" name="url" id="url" />
							</td>
						</tr>
						<tr><td>&nbsp;</td><td>&nbsp;</td></tr>
						<tr>
							<td>&nbsp;</td>
							<td><input type="submit" value="提交"></td>
						</tr>
						<tr><td>&nbsp;</td><td>&nbsp;</td></tr>
					</table>
					</form>
				</div>
			</div>
		</div>
	</div>
<script>
$(function(){
	//加载栏目数据，并实例化
	var browser = $('#browser');
	browser.html('');
	$.ajax({
		type: "POST",
		url: "/admin/news/ajax/ajax_news_left_baner.php",
		dataType: 'html',
		data: {},
		beforeSend: function(){
			browser.html( '加载中...' );
		},
		success: function(data){
			browser.html( data ).treeview();
		}
	});
	
	//监测标题字数
	$('#title').keyup(function(){
		var category_id = $('#parent_id').val();//当前栏目id
		if( category_id == 35 ){//滚动广告栏目
			$('#title').removeAttr('maxlength');
			return '';
		}
		
		var len = $(this).val().length;
		if( len >= 0 && len < 22 ){
			var text = '还可输入'+(22-len)+'个字';
		}else{
			var text = '还可输入0个字';
		}
		$('#title_strlen').html('');
		$('#title_strlen').html(text);
	});
});

//实例化编辑器
var editor = new UE.ui.Editor();
editor.render("content");

//获取栏目
function category_start(i){<!-- i:id号 -->
	$.ajax({
		type: "POST",
		url: "/admin/news/category/ajax/ajax_start.php",
		dataType:'html',
		data: {"id":i,"news":2},
		success: function(data){
			$("#category").html("");
			html = data+'<input type="hidden" name="parent_id" id="parent_id" value="'+i+'"/>';
			$("#category").html(html);
		}
	});
}

//栏目切换
$("select[id^='category_']").live("change", function(){
	var i = $(this).val();
	$.ajax({
		type: "POST",
		url: "/admin/news/category/ajax/ajax_get.php",
		dataType:'html',
		data: {"id":i,"news":2},
		success: function(data){
			$("#category").html("");
			$("#category").html(data);
		}
	});
});

//初始化栏目
category_start(<?php echo $category_id;?>);

//提交检测
function do_submit(){
	if( $('#title').val() == '' ){
		alert('标题不能为空');
		$('#title').focus();
	}else if( $('#url').val() == '' ){
		alert('外部链接不能为空');
		$('#url').focus();
	}else{
		var url = $('#url').val();
		if( url != '' ){
			if( url.length < 7 || url.length > 255 || url.substr(0, 4) != 'http' ){
				alert("外部链接地址必须以http开头且字符长度不能小于7或大于256！");
				$('#url').focus();
				return false;
			}
		}
		return true;
	}
	return false;
}
</script>
</body>
</html>